package com.atguigu.userprofile.mapper;

import com.atguigu.userprofile.bean.UserGroup;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;

import javax.ws.rs.DELETE;
import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author zhangchen
 * @since 2021-05-04
 */


@Mapper
@DS("mysql")
public interface UserGroupMapper extends BaseMapper<UserGroup>
{

    //写入用户分群结果到ck
    @DS("ck")
    @Insert("insert into user_group select #{id}, ${sql} ")
    void insertUserGroupToCK(@Param("id") String userGroupId,@Param("sql") String bitmapAndSql);

    @Select(" select arrayJoin(bitmapToArray(us)) from user_group final where user_group_id = #{id} ")
    @DS("ck")
    List<String> queryUserGroupUsersFromCK(String userGroupId);

    @Select("  select bitmapCardinality(${sql})  ")
    @DS("ck")
    Integer evaluateUserGroupNum(@Param("sql") String sql);

    //根据id删除分群信息
    @DS("ck")
    @Update(" alter table user_group delete where user_group_id = #{id} ")
    void deleteUserGroupById(String id);
}
